<?php

namespace app\api\controller;

use app\common\controller\Api;
use think\Controller;

/**
 * 首页接口
 */
class Index extends Controller
{
    protected $noNeedLogin = ['*'];
    protected $noNeedRight = ['*'];

    /**
     * 首页
     *
     */
    public function index()
    {
        $module = $this->request->module();
        $command = "php think api --force=true --module=$module --output=$module.html";
        chdir(ROOT_PATH);
        $result = shell_exec("$command 2>&1");
        if (strpos($result, 'Build Successed') !== 0) {
            $this->error("生成文档失败：$result");
        }
        return $this->view->fetch(ROOT_PATH . "public/$module.html");
    }

}
